<?php

include_once("SweetBaseGenerator.php");

class SweetHTMLGenerator extends SweetBaseGenerator
{
	public function generate()
	{		
		$output = "<table border'1'><tr><td colspan='7'>Tests: ".$output .= $this->sweetTestSuite->getNumberOfPassedTests().'/'.$this->sweetTestSuite->getNumberOfTests();
		$output .= " Failed: ".$this->sweetTestSuite->getNumberOfFailedTests();
		$output .= " Errored: ".$this->sweetTestSuite->getNumberOfErroredTests();
		$output .= "</td></tr>";
	
		$tests = $this->sweetTestSuite->getTests();

		$i = 0;
		foreach($tests as $className => $reflectedMethods)
		{
			$output .= "<tr><td colspan='7'>".$className."</td></tr>";
			
			
			$passed = $this->sweetTestSuite->getPassedTests();
			$j = 0;
			if(is_array($passed) && sizeof($passed) > 0)
				foreach($passed[$className] as $methodName => $value)
				{
					$output .= "<tr class='passed'><td>Passed</td><td colspan='6'>".$methodName."</td></tr>";
					$j++;
				}
			
			$failed = $this->sweetTestSuite->getFailedTests();
			$j = 0;
			if(is_array($failed) && sizeof($failed) > 0)
				foreach($failed[$className] as $methodName => $exception)
				{
					$output .= "<tr class='failed'><td>Failed</td><td>".$methodName."</td>";
					$output .= "<td>".$exception->seFunction."</td>";
					$output .= "<td>".$exception->seMessage."</td><td>".$exception->seCode."</td>";
					$output .= "<td>".$exception->seFile."</td><td>".$exception->seLine."</td></tr>";
					$j++;
				}			
			
			$errored = $this->sweetTestSuite->getErroredTests();
			$j = 0;
			if(is_array($errored) && sizeof($errored) > 0)
				foreach($errored[$className] as $methodName => $exception)
				{
					$output .= "<tr class='errored'><td>Errored</td><td>".$methodName."</td>";
					$output .= "<td colspan='2'>".$exception->seMessage."</td><td>".$exception->seCode."</td>";
					$output .= "<td>".$exception->seFile."</td><td>".$exception->seLine."</td></tr>";	
					$j++;
				}						
			$i++;
		}

		return $output;
	}
}


?>